#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
char get_choice(void);
char get_first(void);
int get_int(void);
void count(void);
int main(void)
{
	int choice = 0;
	while ((choice = get_choice()) != 'q')
	{
		switch (choice)
		{
		case 'a':printf("Buy low, sell high. \n");
			break;
		case 'b':putchar('\a');
			break;
		case 'c':count();
			break;
		default:printf("Program error!\n");
			break;
		}
	}
	printf("Bye.\n");

	return 0;
}

char get_choice(void)
{
	int ch = 0;
	printf("Enter the letter of your choice:\n");
	printf("a.advice\tb.bell\n");
	printf("c.count\t\tq.quit\n");
	ch = get_first();
	printf("%c\n", ch);
	while ((ch < 'a' || ch>'c') && ch != 'q')
	{
		printf("Please respond with a,b,c,q.\n");
		ch = get_first();
		printf("%c", ch);
	}

	return ch;
}

char get_first(void)
{
	int ch = 0;
	ch = getchar();
	while (ch == '\n' || ch == ' ' || ch == '\t')
		ch = getchar();

	return ch;
}

int get_int(void)
{
	int input = 0;
	char ch = 0;
	while (scanf("%d", &input) != 1)
	{
		while ((ch = getchar()) != '\n')
			putchar(ch);
		printf(" is not an integer.\nPlease enter an ");
		printf("integer value, such as 25,-178,3: ");
	}

	return input;
}

void count(void)
{
	int n = 0, i = 0;
	printf("Count how far? Enter an integer:\n");
	n = get_int();
	for (i = 1; i <= n; i++)
		printf("%d\n", i);
	while (getchar() != '\n')
		continue;
}
